package com.tienon.message.mq;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.tienon.message.entity.Push_App;
import com.tienon.message.mapper.Push_AppMapper;

@Component
@Transactional
public class GetTenAppMsgNeedReSend {

	private static Logger log = Logger.getLogger(GetTenAppMsgNeedReSend.class);

	@Resource
	private Push_AppMapper appDao;

	public List<Push_App> getTenNeedReSendAppMsg() {
		List<Push_App> datas = appDao.findTenNeedReSend();

		for (Push_App data : datas) {

			Integer times = data.getSendTimes();
			if (times == null) {
				times = 0;
			}
			times += 1;
			data.setSendTimes(times);
			data.setState(2);
			data.setSendTime(new Date());
			appDao.updateByPrimaryKeySelective(data);
			log.info("重发:线程:" + Thread.currentThread().getName()
					+ " 更新发送表状态:批次号:" + data.getBatId() + " 流水号:"
					+ data.getSerial() + " 发送序号:" + data.getSplitId() + " 内容:"
					+ data.getMsg() + " 消息的优先级:" + data.getPrior() + " 发送次数:"
					+ data.getSendTimes() + " 发送时间:" + data.getSendTime()
					+ " 更新发送表状态为:发送中(2)");
		}

		return datas;
	}

}
